package com.ibeeking.found.uaa.c.config.advice;

import com.ibeeking.nematos.utils.json.JsonUtils;
import com.ibeeking.nematos.utils.result.ResponseResult;
import com.fasterxml.jackson.core.JsonGenerator;
import com.fasterxml.jackson.databind.SerializerProvider;
import com.fasterxml.jackson.databind.ser.std.StdSerializer;
import org.springframework.http.HttpStatus;

import java.io.IOException;

/**
 * @Author ibeeking
 * @date 2019/6/21
 */
public class ClientOAuthExceptionSerializer extends StdSerializer<ClientOAuthException> {

    public ClientOAuthExceptionSerializer() {
        super(ClientOAuthException.class);
    }

    @Override
    public void serialize(ClientOAuthException value, JsonGenerator jsonGenerator, SerializerProvider serializerProvider) throws IOException {
        jsonGenerator.writeRawValue(JsonUtils.toJsonStr(ResponseResult.fail(HttpStatus.UNAUTHORIZED.value(), value.getMessage())));
    }
}